package bankapplication.com.acme.bankapp.domain.bank;

import bankapplication.com.acme.exceptions.*;

public class SavingsAccount extends AbstractAccount {
  
  public SavingsAccount(double balance){
    this.balance = balance;
  }
  
  @Override
  public void deposit(double x) throws IllegalArgumentException {
    if(x <0.0){
      throw new IllegalArgumentException();
    }
    this.balance +=x;
  }

  @Override
  public void withdraw(double x) throws IllegalArgumentException, 
                       NotEnoughFundsException{
    if(x <0.0){
      throw new IllegalArgumentException();
    }
    if(x>balance){
      throw new NotEnoughFundsException();
    }
    this.balance -=x;
  }
  
  @Override
  public double maximumAmountToWithdraw(){
    return balance;
  }
  
  @Override
  public double getBalance(){
    return this.balance;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    long temp;
    temp = Double.doubleToLongBits(balance);
    result = prime * result + (int) (temp ^ (temp >>> 32));
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    SavingsAccount other = (SavingsAccount) obj;
    if (Double.doubleToLongBits(balance) != Double
        .doubleToLongBits(other.balance))
      return false;
    return true;
  }

  @Override
  public String toString() {
    return "SavingsAccount [balance=" + balance + "]";
  }
  
}
